<?php

/*
 * Created on 2012-11-18
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class Sms {
	
	function sendVerify($mobile){
		$session_account_mobile = session('account_mobile');
		//如果手机号一样使用session中存的验证码
		if($session_account_mobile && $session_account_mobile[mobile]==$mobile){
			$authnum = $session_account_mobile[authnum];
		}else{
		srand((double)microtime()*1000000);//create a random number feed.
		$ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
		$list=explode(",",$ychar);
		for($i=0;$i<4;$i++){
		$randnum=rand(0,35); // 10+26;
		$authnum.=$list[$randnum];
		}
		$autifo = array('mobile'=>$mobile,'time'=>time(),'authnum'=>$authnum);
		session('account_mobile',$autifo);
		}
		$sms_text="您的手机绑定验证码为:".$authnum;
		return $this->send($mobile,$sms_text);
	}
	
	function verify($mobile,$verifyCode){
		
	}
	function send($sms_mob, $sms_text) {
		$url = 'http://sms.webchinese.cn/web_api/?Uid=kmh605&Key=f3665fa85cf592ecfe55&smsMob=' . $sms_mob . '&smsText=' . iconv("UTF-8", "GBK", $sms_text);
		if (function_exists('file_get_contents')) {
			$file_contents = file_get_contents($url);
		} else {
			$ch = curl_init();
			$timeout = 5;
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
			$file_contents = curl_exec($ch);
			curl_close($ch);
		}
		return $file_contents;
	}

}
?>
